/*Replication Routine of Media Exposure of Portfolios as a Measure of Relevance - SPSS syntax.
/*SPSS version: 20.
/*Data set: replication.sav
/*Normalization of the Mean variable, creating the Media variable.
AGGREGATE
  /OUTFILE=* MODE=ADDVARIABLES
  /BREAK=
  /M_min=MIN(Mean).
AGGREGATE
  /OUTFILE=* MODE=ADDVARIABLES
  /BREAK=
  /M_max=MAX(Mean).
compute Media= ((Mean-M_min)/(M_max-M_min))*1.
execute.
delete variables M_min M_max.

/* Table1 - Appendix 
CTABLES
 /VLABELS VARIABLES=Office FOLHA ESTADAO GLOBO DISPLAY=LABEL
 /TABLE Office BY FOLHA [COUNT F40.0, MEAN, STDDEV, MINIMUM, MAXIMUM] + ESTADAO [COUNT F40.0, MEAN, STDDEV, MINIMUM, MAXIMUM] + GLOBO [COUNT F40.0, MEAN, STDDEV, MINIMUM, MAXIMUM]
 /CATEGORIES VARIABLES=Office ORDER=A KEY=VALUE EMPTY=EXCLUDE.

/*Performing the Factor Anlaysis with Media and generating variable Factor_1 - Tables 3, 4 and 5.
FACTOR
  /VARIABLES Media Legislative_Production Positions Budget
  /MISSING LISTWISE 
  /ANALYSIS Media Legislative_Production Positions Budget
  /PRINT INITIAL EXTRACTION FSCORE
  /CRITERIA MINEIGEN(1) ITERATE(25)
  /EXTRACTION PC
  /ROTATION NOROTATE
  /SAVE REG(ALL)
  /METHOD=CORRELATION.
/*Performing the Factor Anlaysis without Media and generating variable Factor_2 - Tables 3 and 5.
FACTOR
  /VARIABLES Legislative_Production Positions Budget
  /MISSING LISTWISE 
  /ANALYSIS Legislative_Production Positions Budget
  /PRINT INITIAL EXTRACTION FSCORE
  /CRITERIA MINEIGEN(1) ITERATE(25)
  /EXTRACTION PC
  /ROTATION NOROTATE
  /SAVE REG(ALL)
  /METHOD=CORRELATION.
/* Table 2 - Cronbach's Alpha Test /* Kaiser-Meier-Olkin and	Barllets Test of Sphericity are avaible on the factor analysis with media command above. 
RELIABILITY 
  /VARIABLES=Media Legislative_Production Positions Budget 
  /SCALE('ALL VARIABLES') ALL 
  /MODEL=ALPHA 
  /STATISTICS=DESCRIPTIVE SCALE CORR 
  /SUMMARY=TOTAL.
/*Normalizing variables Factor_1 and Factor_2.
AGGREGATE
  /OUTFILE=* MODE=ADDVARIABLES
  /BREAK=
  /F1_min=MIN(Factor_1).
AGGREGATE
  /OUTFILE=* MODE=ADDVARIABLES
  /BREAK=
  /F1_max=MAX(Factor_1).
compute Factor_1_N= ((Factor_1-F1_min)/(F1_max-F1_min))*1.
execute.
delete variables F1_min F1_max.
  
AGGREGATE
  /OUTFILE=* MODE=ADDVARIABLES
  /BREAK=
  /F2_min=MIN(Factor_2).
AGGREGATE
  /OUTFILE=* MODE=ADDVARIABLES
  /BREAK=
  /F2_max=MAX(Factor_2).
compute Factor_2_N= ((Factor_2-F2_min)/(F2_max-F2_min))*1.
execute.
delete variables F2_min F2_max.

/*Creating a table with mean and standard deviation by portfolio for the following variables: Media, Factor_1_N and Factor_2_N. 
CTABLES
  /VLABELS VARIABLES=Office Media Factor_1_N Factor_2_N DISPLAY=LABEL
  /TABLE Office BY Media [MEAN, STDDEV] + Factor_1_N [MEAN, STDDEV] + Factor_2_N [MEAN, STDDEV]
  /CATEGORIES VARIABLES=Office ORDER=A KEY=VALUE EMPTY=EXCLUDE.

/*In order to facilitate the production of graphs 1, 2 and 3, we use the table above to create a new data set, called "data_graphs". Please open the data set to perform the commands below.
/*Graph 1.
/*Creating upper and lower dispersion of the data.
COMPUTE Media_lower=Media - Media_SD. 
EXECUTE.
COMPUTE Media_Upper=Media + Media_SD. 
EXECUTE.
/*Plotting Graph 1 - Note that we use a template file called "gr�ficos_BPSR.sgt" to facilitate the creation of the graph. Please download the file and change line 97 to your directory. 
GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=Ministry 
    MAXIMUM(Media_Upper)[name="MAXIMUM_Media_Upper"] MINIMUM(Media_lower)[name="MINIMUM_Media_lower"] 
    MEAN(Media)[name="MEAN_Media"] MISSING=LISTWISE REPORTMISSING=NO
  /GRAPHSPEC SOURCE=INLINE
   TEMPLATE=[
    "C:\Users\Paulo\Documents\Documents\IC Luis\gr�ficos_BPSR.sgt"].
BEGIN GPL
  SOURCE: s=userSource(id("graphdataset"))
  DATA: Ministry=col(source(s), name("Ministry"), unit.category())
  DATA: MAXIMUM_Media_Upper=col(source(s), name("MAXIMUM_Media_Upper"))
  DATA: MINIMUM_Media_lower=col(source(s), name("MINIMUM_Media_lower"))
  DATA: MEAN_Media=col(source(s), name("MEAN_Media"))
  GUIDE: axis(dim(1), label("Ministry"))
  GUIDE: axis(dim(2), label("M�ximo(Media_Upper), M�nimo(Media_lower), M�dia(Media)"))
  SCALE: linear(dim(2), include(0))
  ELEMENT: interval(position(region.spread.range(Ministry*(MINIMUM_Media_lower+MAXIMUM_Media_Upper))
    ), shape(shape.ibeam))
  ELEMENT: point(position(Ministry*MEAN_Media), shape(shape.circle))
END GPL.

/* Graph 2.
/*Creating upper and lower dispersion of the data.
COMPUTE Factor_1_N_lower=Factor_1_N - Factor_1_N_SD. 
EXECUTE.
COMPUTE Factor_1_N_upper=Factor_1_N + Factor_1_N_SD. 
EXECUTE.
/*Plotting Graph 2 - Note that we use a template file called "gr�ficos_BPSR.sgt" to facilitate the creation of the graph. Please dowload the file and change line 125 to your directory.
GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=Ministry 
    MAXIMUM(Factor_1_N_upper)[name="MAXIMUM_Factor_1_N_upper"] 
    MINIMUM(Factor_1_N_lower)[name="MINIMUM_Factor_1_N_lower"] MEAN(Factor_1_N)[name="MEAN_Factor_1_N"] 
    MISSING=LISTWISE REPORTMISSING=NO
  /GRAPHSPEC SOURCE=INLINE
   TEMPLATE=["C:\Users\Paulo\Documents\Documents\IC Luis\gr�ficos_BPSR.sgt"].
BEGIN GPL
  SOURCE: s=userSource(id("graphdataset"))
  DATA: Ministry=col(source(s), name("Ministry"), unit.category())
  DATA: MAXIMUM_Factor_1_N_upper=col(source(s), name("MAXIMUM_Factor_1_N_upper"))
  DATA: MINIMUM_Factor_1_N_lower=col(source(s), name("MINIMUM_Factor_1_N_lower"))
  DATA: MEAN_Factor_1_N=col(source(s), name("MEAN_Factor_1_N"))
  GUIDE: axis(dim(1), label("Ministry"))
  GUIDE: axis(dim(2), label("M�ximo(Factor_1_N_upper), M�nimo(Factor_1_N_lower), ",
    "M�dia(Factor_1_N)"))
  SCALE: linear(dim(2), include(0))
  ELEMENT: interval(position(region.spread.range(Ministry*(MINIMUM_Factor_1_N_lower+
    MAXIMUM_Factor_1_N_upper))), shape(shape.ibeam))
  ELEMENT: point(position(Ministry*MEAN_Factor_1_N), shape(shape.circle))
END GPL.

/*Plotting Graph 3. Note that we use a template file called "Graph 3.sgt" to facilitate the creation of the graph. Please download the file and change line 147 to your directory. 
GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=Ministry MEAN(Factor_1_N) MEAN(Factor_2_N) 
    MISSING=LISTWISE REPORTMISSING=NO
    TRANSFORM=VARSTOCASES(SUMMARY="#SUMMARY" INDEX="#INDEX")
  /GRAPHSPEC SOURCE=INLINE
   TEMPLATE=["C:\Users\Paulo\Documents\Documents\IC Luis\Dados Finais\Graph 3.sgt"].
BEGIN GPL
  SOURCE: s=userSource(id("graphdataset"))
  DATA: Ministry=col(source(s), name("Ministry"), unit.category())
  DATA: SUMMARY=col(source(s), name("#SUMMARY"))
  DATA: INDEX=col(source(s), name("#INDEX"), unit.category())
  GUIDE: axis(dim(1), label("Ministry"))
  GUIDE: axis(dim(2), label("Factor_1_N"))
  GUIDE: legend(aesthetic(aesthetic.color.exterior), label(""))
  SCALE: linear(dim(2), include(0))
  SCALE: cat(aesthetic(aesthetic.color.exterior), include("0", "1"))
  ELEMENT: point(position(Ministry*SUMMARY), color.exterior(INDEX))
END GPL.

/*Plotting Graph 4 - We use again the replication file - We also use a template file called "gr�ficos_BPSR.sgt" to facilitate the creation of the graph. Please download the file to use the command and change line 166 to your directory.

GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=Office MEAN(Factor_1_N)[name="MEAN_Factor_1_N"] Presidency MISSING=LISTWISE REPORTMISSING=NO 
  /GRAPHSPEC SOURCE=INLINE 
   TEMPLATE=["C:\Users\Paulo\Documents\Documents\IC Luis\gr�ficos_BPSR.sgt"]. 
BEGIN GPL 
  SOURCE: s=userSource(id("graphdataset")) 
  DATA: Office=col(source(s), name("Office"), unit.category()) 
  DATA: MEAN_Factor_1_N=col(source(s), name("MEAN_Factor_1_N")) 
  DATA: Presidency=col(source(s), name("Presidency"), unit.category()) 
  GUIDE: axis(dim(1), label("Office")) 
  GUIDE: axis(dim(2), label("MEAN_Factor_1_N")) 
  GUIDE: legend(aesthetic(aesthetic.color.exterior), label("Presidency")) 
  SCALE: linear(dim(2), include(0)) 
  ELEMENT: point(position(Office*MEAN_Factor_1_N), color.exterior(Presidency)) 
END GPL.

/*End of the Script/*



